#include "BSW_UART.h"


uint8_t Gloable_u8MCU_TO_PC_UART_RxBit;				//单字节接收缓冲
uint32_t Gloable_u32MCU_TO_PC_UART_RxLen;			//最终传递出去的单帧长度
uint32_t Gloable_u32MCU_TO_PC_UART_RxCnt = 0;		//接收计数
uint8_t Gloable_u8MCU_TO_PC_UART_RxArr[300];    	//数组接收缓冲
uint8_t Gloable_u8MCU_TO_PC_UART_CMDNum = 8;		//命令语句长度
uint16_t Gloable_u16MCU_TO_PC_UART_DATANum = 259;		//数据帧长度
/*
 * MCU TO PC UART START
 */

// 串口输出字符函数
void uart_putchar(char c) {
    HAL_UART_Transmit(&MCU_TO_PC_UART_port, (uint8_t*)&c, 1, HAL_MAX_DELAY);
}

/*
 * MCU TO PC UART END
 */


/*
 * BSW UART START
 */
void BSW_UART_Init(void) {
    set_putchar_function(uart_putchar);
    HAL_UART_Receive_IT(&MCU_TO_PC_UART_port, (uint8_t *)&Gloable_u8MCU_TO_PC_UART_RxBit, 1);
    __HAL_TIM_CLEAR_IT(&htim6, TIM_IT_UPDATE);
    HAL_TIM_Base_Start_IT(&htim6);
    my_printf(">>>>>MCU TO PC UART is ready\r\n");
    my_printf(">>>>>MCU TO PC UART Receive NVIC is open\r\n");
    my_printf(">>>>>MCU TO PC UART TIM6 NVIC is Start\r\n");
}
/*
 * BSW UART END
 */



//void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
//{
//	if (CalculateCRC16(rx_data,back_num-2) == rx_data[back_num-2]*256 + rx_data[back_num-1])
//	{
//		BSP_W25Qx_Write(rx_data, rx_data[back_num-3]*256, back_num-3);
//		uint8_t read_flash[256];
//		BSP_W25Qx_Read(read_flash, rx_data[back_num-3]*256, back_num-3);
//		HAL_UART_Transmit(&huart3, (uint8_t *)&read_flash, back_num-3,0xFFFF);
//		memset(rx_data,0x00,sizeof(rx_data));
//		HAL_UART_Receive_IT(&MCU_TO_PC_UART_port, (uint8_t *)&rx_data, back_num);
//	}
//}
